//
//  OilChooseView.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/6/12.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "OilChooseView.h"

@implementation OilChooseView


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
          //适配
        CGFloat plusCount;
        if (iPhone5) {
            plusCount = 10;
        }else {
            plusCount = 20;
        }
        
        UILabel *Label = [[UILabel alloc] initWithFrame:CGRectMake(15,plusCount,100,14)];
        Label.text = @"充值面额";
        Label.font = [UIFont systemFontOfSize:14];
        [self addSubview:Label];
        Label.textColor = [UIColor grayColor];
        
        
        NSArray *arr = @[@"100元",@"500元"];
        
        CGFloat BtnW = WIDTH/4.5;
        CGFloat BtnMargin = (WIDTH-WIDTH/4.5*2)/3;
        
        for (int i = 0; i < arr.count; ++i) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            
            button.layer.cornerRadius = 5;
            button.layer.masksToBounds = YES;
            button.layer.borderWidth = 0.5;
            button.layer.borderColor = [UIColor lightGrayColor].CGColor;
            
            button.titleLabel.font = [UIFont systemFontOfSize:15];
            [button setTitle:[NSString stringWithFormat:@"%@",arr[i]] forState:UIControlStateNormal];
            [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            button.frame = CGRectMake(BtnMargin+(BtnW+BtnMargin)*i,CGRectGetMaxY(Label.frame)+10,BtnW,BtnW/2);
            
            
            button.tag = 100+i;
            [button addTarget:self action:@selector(moneyPayDidClick:) forControlEvents:UIControlEventTouchUpInside];
            if (i==0) {
                [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                [button setBackgroundColor:DEFAULT_COLOR];
            }
            
            [self addSubview:button];
        }
        
    }
    return self;
}

- (void)moneyPayDidClick:(UIButton *)sender
{
    
    for (UIButton *tempBtn in self.subviews) {
        
        if (tempBtn.tag > 99) {
            [tempBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [tempBtn setBackgroundColor:[UIColor whiteColor]];
            
        }
        
        if (tempBtn.tag == sender.tag) {
            
            [sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [sender setBackgroundColor:DEFAULT_COLOR];
        }
    }
    
    if ([self.delegate respondsToSelector:@selector(OilChooseViewDidClick:)]) {
        
        [self.delegate OilChooseViewDidClick:sender];
    }
}
@end
